package com.jxc.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.jxc.model.User;
import com.jxc.util.DBConnection;

public class UserDao {

	public User checkLogin(String username, String password) {
		User user = null;
		Connection conn = null;
		Statement st = null;
		ResultSet rs = null;
		String sql = "";
		try {
			conn = DBConnection.getConnection();
			st = conn.createStatement();
			sql = "select * from t_user where user_name = '" + username
					+ "' and user_pass = '" + password + "'";
			System.out.println(sql);
			rs = st.executeQuery(sql);
			if(rs.next()){
				user = new User();
				user.setUserId( rs.getInt("user_id") );
				user.setUserName( rs.getString("user_name") );
				user.setUserLevel( rs.getInt("user_level") );
				user.setUserSex( rs.getInt("user_sex") );
				user.setUserTel( rs.getString("user_tel") );
				user.setUserEmail( rs.getString("user_email") );
				user.setUserAddr( rs.getString("user_addr") );
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			DBConnection.free(conn, st, rs);
		}
		return user;
	}
}
